(:  
   Merge (ordered by the 1st date in each item)
   2 or more "display" files
 :)

declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
<display>{
	let $p := $arguments[1]
	let $c := $arguments[2]
	let $posts := doc($p)/display/item
	let $comments := doc($c)/display/item
  for $post at $pos in $posts
  let $id := jj:get-info($post,"id")
  let $nextid := if ($pos = count($posts)) then "" else jj:get-info($posts[$pos+1],"id")
  order by $post/info[@name="time"]/time/date[1] 
  return
  ($post, 
  if ($id = $nextid) then ()
  else for $comment in $comments[jj:get-info(.,"postid") = $id]
  order by $comment/info[@name="time"]/time/date[1] 
  return $comment)
}</display>
